home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_libghttp.idb / usr / freeware / include / ghttp.h.z / ghttp.h
Encoding:
C/C++ Source or Header  |  1999-07-16  |  4.9 KB  |  249 lines

  1. /*
  2.  * ghttp.h -- A public interface to common http functions
  3.  * Created: Christopher Blizzard <blizzard@appliedtheory.com>, 21-Aug-1998
  4.  *
  5.  * Copyright (C) 1998 Free Software Foundation
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Library General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2 of the License, or (at your option) any later version.
  11.  *
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Library General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Library General Public
  18.  * License along with this library; if not, write to the Free
  19.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  */
  21.  
  22. #ifndef GHTTP_H
  23. #define GHTTP_H
  24.  
  25. #include <ghttp_constants.h>
  26. #include <time.h>
  27.  
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif __cplusplus
  31.  
  32. typedef struct _ghttp_request ghttp_request;
  33.  
  34. typedef enum ghttp_type_tag
  35. {
  36.   ghttp_type_get = 0,
  37.   ghttp_type_options,
  38.   ghttp_type_head,
  39.   ghttp_type_post,
  40.   ghttp_type_put,
  41.   ghttp_type_delete,
  42.   ghttp_type_trace,
  43.   ghttp_type_connect,
  44.   ghttp_type_propfind,
  45.   ghttp_type_proppatch,
  46.   ghttp_type_mkcol,
  47.   ghttp_type_copy,
  48.   ghttp_type_move,
  49.   ghttp_type_lock,
  50.   ghttp_type_unlock
  51. } ghttp_type;
  52.  
  53. typedef enum ghttp_sync_mode_tag
  54. {
  55.   ghttp_sync = 0,
  56.   ghttp_async,
  57. } ghttp_sync_mode;
  58.  
  59. typedef enum ghttp_status_tag
  60. {
  61.   ghttp_error = -1,
  62.   ghttp_not_done,
  63.   ghttp_done,
  64. } ghttp_status;
  65.  
  66. typedef enum ghttp_proc_tag
  67. {
  68.   ghttp_proc_none = 0,
  69.   ghttp_proc_request,
  70.   ghttp_proc_response_hdrs,
  71.   ghttp_proc_response,
  72. } ghttp_proc;
  73.  
  74. typedef struct ghttp_current_status_tag
  75. {
  76.   ghttp_proc         proc;        /* what's it doing? */
  77.   int                bytes_read;  /* how many bytes have been read? */
  78.   int                bytes_total; /* how many total */
  79. } ghttp_current_status;
  80.  
  81. /* create a new request object */
  82. ghttp_request *
  83. ghttp_request_new(void);
  84.  
  85. /* delete a current request object */
  86. void
  87. ghttp_request_destroy(ghttp_request *a_request);
  88.  
  89. /* Validate a uri
  90.  * This will return -1 if a uri is invalid
  91.  */
  92. int
  93. ghttp_uri_validate(char *a_uri);
  94.  
  95. /* Set a uri in a request
  96.  * This will return -1 if the uri is invalid
  97.  */
  98.  
  99. int
  100. ghttp_set_uri(ghttp_request *a_request, char *a_uri);
  101.  
  102. /* Set a proxy for a request
  103.  * This will return -1 if the uri is invalid
  104.  */
  105.  
  106. int
  107. ghttp_set_proxy(ghttp_request *a_request, char *a_uri);
  108.  
  109. /* Set a request type
  110.  * This will return -1 if the request type is invalid or
  111.  * unsupported
  112.  */
  113.  
  114. int
  115. ghttp_set_type(ghttp_request *a_request, ghttp_type a_type);
  116.  
  117. /* Set the body.
  118.  * This will return -1 if the request type doesn't support it
  119.  */
  120.  
  121. int
  122. ghttp_set_body(ghttp_request *a_request, char *a_body, int a_len);
  123.  
  124. /* Set whether or not you want to use sync or async mode.
  125.  */
  126.  
  127. int
  128. ghttp_set_sync(ghttp_request *a_request,
  129.            ghttp_sync_mode a_mode);
  130.  
  131. /* Prepare a request.
  132.  * Call this before trying to process a request or if you change the
  133.  * uri.
  134.  */
  135.  
  136. int
  137. ghttp_prepare(ghttp_request *a_request);
  138.  
  139. /* Set the chunk size
  140.  * You might want to do this to optimize for different connection speeds.
  141.  */
  142.  
  143. void
  144. ghttp_set_chunksize(ghttp_request *a_request, int a_size);
  145.  
  146. /* Set a random request header
  147.  */
  148.  
  149. void
  150. ghttp_set_header(ghttp_request *a_request,
  151.          const char *a_hdr, const char *a_val);
  152.  
  153. /* Process a request
  154.  */
  155.  
  156. ghttp_status
  157. ghttp_process(ghttp_request *a_request);
  158.  
  159. /* Get the status of a request
  160.  */
  161.  
  162. ghttp_current_status
  163. ghttp_get_status(ghttp_request *a_request);
  164.  
  165. /* Get the value of a random response header
  166.  */
  167.  
  168. const char *
  169. ghttp_get_header(ghttp_request *a_request,
  170.          const char *a_hdr);
  171.  
  172. /* Abort a currently running request.
  173.  */
  174. int
  175. ghttp_close(ghttp_request *a_request);
  176.  
  177. /* Clean a request
  178.  */
  179. void
  180. ghttp_clean(ghttp_request *a_request);
  181.  
  182. /* Get the socket associated with a particular connection
  183.  */
  184.  
  185. int
  186. ghttp_get_socket(ghttp_request *a_request);
  187.  
  188. /* get the return entity body
  189.  */
  190.  
  191. char *
  192. ghttp_get_body(ghttp_request *a_request);
  193.  
  194. /* get the returned length
  195.  */
  196.  
  197. int
  198. ghttp_get_body_len(ghttp_request *a_request);
  199.  
  200. /* Get an error message for a request that has failed.
  201.  */
  202.  
  203. const char *
  204. ghttp_get_error(ghttp_request *a_request);
  205.  
  206. /* Parse a date string that is one of the standard
  207.  * date formats
  208.  */
  209.  
  210. time_t
  211. ghttp_parse_date(char *a_date);
  212.  
  213. /* Return the status code.
  214.  */
  215.  
  216. int
  217. ghttp_status_code(ghttp_request *a_request);
  218.  
  219. /* Return the reason phrase.
  220.  */
  221.  
  222. const char *
  223. ghttp_reason_phrase(ghttp_request *a_request);
  224.  
  225. /* Set your username/password pair 
  226.  */
  227.  
  228. int
  229. ghttp_set_authinfo(ghttp_request *a_request,
  230.            const char *a_user,
  231.            const char *a_pass);
  232.            
  233.  
  234.  /* Set your username/password pair for proxy
  235.   */
  236.  
  237. int
  238. ghttp_set_proxy_authinfo(ghttp_request *a_request,
  239.              const char *a_user,
  240.              const char *a_pass);
  241.  
  242.  
  243. #ifdef __cplusplus
  244. }
  245. #endif /* __cplusplus */
  246.  
  247.  
  248. #endif /* GHTTP_H */
  249.